var config = require('../config')
var sounddb = require('./sound.db')
var musicdb = require('./music.db')

function client(isMusic = false){
    if(isMusic){
        return musicdb.client();
    }else{
        return sounddb.client();
    }
}

function addtag(isMusic, fileid, maintag, childtag, grandsontag, func) {
    var db = isMusic ? musicdb : sounddb;
    db.addtag(fileid,maintag,childtag,grandsontag,func);
}

function getfileinfo(isMusic, fileid, cb) {
    var db = isMusic ? musicdb : sounddb;
    db.getfileinfo(fileid,cb);
}

function readfile(isMusic, fileid, cb) {
    var db = isMusic ? musicdb : sounddb;
    var resourcepath = isMusic ? config.musicResourcePath : config.soundResourcePath;
    db.readfile(resourcepath, fileid,cb);
}

function getallmaitags(isMusic, cb) {
    var db = isMusic ? musicdb : sounddb;
    db.getallmaitags(cb);
}

function getfiletags(isMusic, fileid, cb) {
    var db = isMusic ? musicdb : sounddb;
    db.getfiletags(fileid,cb);
}

function setfileinfo(isMusic, fileid, info, cb) {
    var db = isMusic ? musicdb : sounddb;
    db.setfileinfo(fileid,info,cb);
}

function gettagtree(isMusic, cb) {
    var db = isMusic ? musicdb : sounddb;
    db.gettagtree(cb);
}

module.exports = {
    client,
    addtag,
    getfileinfo,
    readfile,
    getallmaitags,
    getfiletags,
    setfileinfo,
    gettagtree,
}